package org.aeon.gamechatnest.mapper;

import org.aeon.gamechatnest.pojo.TextChannel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 89342
 * @description 针对表【text_channel(文字频道表)】的数据库操作Mapper
 * @createDate 2024-05-09 09:25:50
 * @Entity org.aeon.gamechatnest.pojo.TextChannel
 */
@Mapper
public interface TextChannelMapper {
    /**
     * 新增频道
     *
     * @param textChannel
     * @return
     */
    int add(TextChannel textChannel);

    /**
     * 通过频道id删除频道
     *
     * @param tcId
     * @return
     */
    @Delete("delete from text_channel where tc_id=#{tcId}")
    int deleteByTcId(Long tcId);

    /**
     * 通过频道id修改频道
     *
     * @param textChannel
     * @return
     */
    int updateByTcId(TextChannel textChannel);

    /**
     * 通过频道名称模糊查询频道
     *
     * @param name
     * @return
     */
    List<TextChannel> getByName(@Param("name") String name);

    /**
     * 通过频道id查询频道
     *
     * @param tcId
     * @return
     */
    @Select("SELECT server_id,name,introduce FROM text_channel WHERE tc_id=#{tcId}")
    TextChannel getByTcId(@Param("tcId") Long tcId);

    /**
     * 查询存在
     *
     * @param tcId
     * @return
     */
    @Select("SELECT COUNT(tc_id) FROM text_channel WHERE tc_id=#{tcId}")
    boolean isExist(@Param("tcId") Long tcId);

    /**
     * 通过频道id查询频道所属的服务器id
     *
     * @param tcId
     * @return
     */
    @Select("SELECT server_id FROM text_channel WHERE tc_id=#{tcId}")
    Long getServerIdByChannelId(Long tcId);

    /**
     * 通过服务器id删除频道
     *
     * @param serverId
     * @return
     */
    int deleteByServerId(Long serverId);

    /**
     * 通过服务器id查询频道
     *
     * @param server
     * @return
     */
    @Select("SELECT tc_id,name,introduce FROM text_channel WHERE server_id=#{server}")
    List<TextChannel> getByServerId(Long server);

}




